package com.iflytek.springboot_medicine.service;

import com.iflytek.springboot_medicine.entity.Medicine;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface MedicineRepository extends JpaRepository<Medicine, Integer> {
    // 分页和模糊查询方法
    @Query("SELECT m FROM Medicine m JOIN m.cate c WHERE (:name IS NULL OR m.name LIKE CONCAT('%', :name, '%')) AND (:category IS NULL OR c.name LIKE CONCAT('%', :category, '%'))")
    Page<Medicine> findByMedicineNameAndCategoryName(@Param("name") String name, @Param("category") String category, Pageable pageable);
    Medicine deleteById(int id);
    Medicine findByName(String name);
}
